package com.jian.bus.service.impl;

import com.jian.bus.pojo.Goods;
import com.jian.bus.pojo.Sales;
import com.jian.bus.pojo.Salesback;
import com.jian.bus.mapper.SalesbackMapper;
import com.jian.bus.service.GoodsService;
import com.jian.bus.service.SalesService;
import com.jian.bus.service.SalesbackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jian.bus.vo.SalesbackVo;
import com.jian.sys.common.WebUtils;
import com.jian.sys.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 剑
 * @since 2020-01-26
 */
@Service
@Transactional
public class SalesbackServiceImpl extends ServiceImpl<SalesbackMapper, Salesback> implements SalesbackService {
    @Autowired
    SalesService salesService;
    @Autowired
    GoodsService goodsService;
    @Override
    public void saveSalesbackInfo(Integer id,String remark,Integer number) {
        Sales sales = salesService.getById(id);
        Goods goods = goodsService.getById(sales.getGoodsid());
        goods.setNumber(goods.getNumber()+number);
        goodsService.updateById(goods);
        Salesback salesback=new Salesback();
        salesback.setCustomername(sales.getCustomername());
        salesback.setGoodsname(sales.getGoodsname());
        salesback.setSize(sales.getSize());
        salesback.setCustomerid(sales.getCustomerid());
        salesback.setGoodsid(sales.getGoodsid());
        salesback.setSalebackprice(sales.getSaleprice());
        salesback.setSalesbacktime(new Date());
        salesback.setNumber(number);
        salesback.setRemark(remark);
        User user= (User) WebUtils.getSession().getAttribute("user");
        salesback.setOperateperson(user.getName());
        salesback.setPaytype(sales.getPaytype());

        this.baseMapper.insert(salesback);
    }
}
